package com.liufei.class06;

import com.liufei.common.TreeNode;


// https://leetcode.cn/problems/symmetric-tree/description/
public class Code03_SymmetricTree {

    public boolean isSymmetric(TreeNode root) {
        return isSymmetricTree(root, root);
    }

    public boolean isSymmetricTree(TreeNode head1, TreeNode head2) {
        if (head1 == null ^ head2 == null) {
            return false;
        }

        if (head1 == null && head2 == null) {
            return true;
        }

        return head1.val == head2.val && isSymmetricTree(head1.left, head2.right) && isSymmetricTree(head1.right, head2.left);
    }
}
